#ifndef U2LogManager_H
#define U2LogManager_H

#include "U2PreRequest.h"
#include "U2MemoryAllocatorConfig.h"
#include "U2Singleton.h"
#include "U2Log.h"


U2EG_NAMESPACE_BEGIN


class _U2Share U2LogManager : public U2Singleton<U2LogManager>, public LogAlloc
{
public:
	U2_AUTO_MUTEX // public to allow external locking

    U2LogManager(void);
	~U2LogManager(void);
	static U2LogManager& getSingleton(void);
	static U2LogManager* getSingletonPtr(void);

    
    /** Creates a new log with the given name.
    @param
        name The name to give the log e.g. 'Ogre.log'
    @param
        defaultLog If true, this is the default log output will be
        sent to if the generic logging methods on this class are
        used. The first log created is always the default log unless
        this parameter is set.
    @param
        debuggerOutput If true, output to this log will also be
        routed to the debugger's output window.
    @param
        suppressFileOutput If true, this is a logical rather than a physical
		log and no file output will be written. If you do this you should
		register a LogListener so log output is not lost.
    */
    U2Log* createLog( const U2String& name, bool defaultLog = false, bool debuggerOutput = true, 
		bool suppressFileOutput = false);

    /** Retrieves a log managed by this class.
    */
    U2Log* getLog( const U2String& name);

    /** Returns a pointer to the default log.
    */
    U2Log* getDefaultLog();

	/** Closes and removes a named log. */
	void destroyLog(const U2String& name);
	/** Closes and removes a log. */
	void destroyLog(U2Log* log);

	/** Sets the passed in log as the default log.
    @returns The previous default log.
    */
    U2Log* setDefaultLog(U2Log* newLog);

    /** Log a message to the default log.
    */
    void logMessage( const U2String& message, LogMessageLevel lml = LML_NORMAL, 
        bool maskDebug = false);

    /** Log a message to the default log (signature for backward compatibility).
    */
    void logMessage( LogMessageLevel lml, const U2String& message,  
		bool maskDebug = false) { logMessage(message, lml, maskDebug); }

	/** Get a stream on the default log. */
	U2Log::Stream stream(LogMessageLevel lml = LML_NORMAL, 
		bool maskDebug = false);

	/** Sets the level of detail of the default log.
    */
    void setLogDetail(LoggingLevel ll);
    
        
protected:
	typedef std::map<U2String, U2Log*, std::less<U2String> >	LogList;

	/// A list of all the logs the manager can access
	LogList							m_logs;

	/// The default log to which output is done
	U2Log*							m_pDefaultLog;
};

U2EG_NAMESPACE_END

#endif